<?php

	include "includes".DIRECTORY_SEPARATOR."start_session.php";
	
	
	if ( !defined('USERNAME') || !defined('GROUP') || GROUP != "admin" )
	{
		header("Location: manage_login.php");
		exit;
	}
	
	include "includes".DIRECTORY_SEPARATOR."header.php";
	main_header(10);
	
	
	//include second header

	include "includes".DIRECTORY_SEPARATOR."include_admin_secondary_header_index.php";
	second_header( 6 );


?>

<tr>
    <td colspan="2" class="text1" height="60" valign="top"></td>
</tr>        
<tr>
    <td style="padding-left:20;padding-right:20;padding-bottom:20" background="images/white.jpg" valign="top" width="400" height="100%">
 <?php
           
		   $form_username = USERNAME;
            
            $form=<<<GATA
               <h4>Schimbare parola</h4>	
                <br><br>
               <form method = POST action = "admin_manage_my_account.php">
               <table border = 0>
               <tr><td><h4>Nume</td><td>$form_username</td></tr></h4>
               <tr><td><h4>Parola noua</td><td><input type = "password" name = "pass1"></td></tr></h4>
			   <tr><td><h4>Reintroduce parola noua</td><td><input type = "password" name = "pass2"></td></tr></h4>
               <tr><td><input type = submit value = "Modifica parola" ></td></tr>
               </table>
               </form>
GATA;
            echo $form;
 
 
 			 $tablou = array("pass1" => "",
							 "pass2" => ""
							)	;
			 $erori = "";
			 $tablou_erori = array("parola1" => "Nu ati completat prima parola. Va rugam reincercati !<br />",
							 "parola2" => "Nu ati completat a doua parola. Va rugam reincercati !<br />",
							 "parola3" => "Parolele introduse nu coincid. Va rugam reincercati !<br />",
							 "parola4" => "Parola incorecta. Va rugam reincercati !<br />"
							 );
 
 
 
 			if($_SERVER['REQUEST_METHOD'] == 'POST')
				  
			{
				  	$ok = 1;
					
					#verifica parola 1
					if(empty($_POST["pass1"]))
					{
						$erori = $erori.$tablou_erori["parola1"];
						$ok = 0;									
					}
					else
					{
						$tablou["pass1"] = trim( $_POST["pass1"] );
						
						if ( empty ( $tablou["pass1"] ) )
						{
							$erori = $erori.$tablou_erori["parola4"];
							$ok = 0;									
						}
					}
					
					#verifica parola 1
					if(empty($_POST["pass2"]))
					{
						$erori = $erori.$tablou_erori["parola2"];
						$ok = 0;									
					}
					else
					{
						$tablou["pass2"] = trim( $_POST["pass2"] );
						
						if ( empty ( $tablou["pass2"] ) )
						{
							$erori = $erori.$tablou_erori["parola4"];
							$ok = 0;									
						}
					}
					
					if( !empty($tablou["pass1"]) && !empty($tablou["pass2"]) )
					{
						if ( $tablou["pass1"] !== $tablou["pass2"] )
						{
							$erori = $erori.$tablou_erori["parola3"];
							$ok = 0;
						}					
					}
					else
					{
						$ok = 0;
					}
					
					
					if($ok != 1)
					{
						echo "<font color=\"red\">".$erori."</font>";
					}
					else
					{						
						$u = mysqli_query($dbc,"UPDATE  `anc`.`utilizatori` SET  `parola` =  '$tablou[pass1]' WHERE  `utilizatori`.`nume` = '$form_username' ");
							
						echo "<br />";	
						echo "<font color=\"#00CC00\">Parola a fost modificata cu succes ! </font>";	
					}
				}
 
 ?>
    </td>
</tr>


<?php
	include "includes".DIRECTORY_SEPARATOR."footer.php";
?>
